home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
prolog
/
sbprolog
/
amiga
/
builtin2.zoo
/
name.c
< prev
next >
Wrap
C/C++ Source or Header
|
1988-08-15
|
3KB
|
99 lines
/************************************************************************
* *
* The SB-Prolog System *
* Copyright SUNY at Stony Brook, 1986; University of Arizona, 1987 *
* *
************************************************************************/
/*-----------------------------------------------------------------
SB-Prolog is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY. No author or distributor
accepts responsibility to anyone for the consequences of using it
or for whether it serves any particular purpose or works at all,
unless he says so in writing. Refer to the SB-Prolog General Public
License for full details.
Everyone is granted permission to copy, modify and redistribute
SB-Prolog, but only under the conditions described in the
SB-Prolog General Public License. A copy of this license is
supposed to have been given to you along with SB-Prolog so you
can know your rights and responsibilities. It should be in a
file named COPYING. Among other things, the copyright notice
and this notice must be preserved on all copies.
------------------------------------------------------------------ */
/* name.c */
#include "builtin.h"
word ptr;
extern word insert();
char perm = PERM;
b_NAME0()
/* (X,L), L is made to be the string of the name of X */
{
struct psc_rec *p;
char *name;
int l, i;
word nlist;
register word op1;
register pw top;
op1 = gregc(1); deref(op1);
if (!isconstr(op1)) {
printf("Error: name0, illegal argument\n");
Fail0; return;
}
p = get_str_psc(op1);
name = get_name(p);
l = get_length(p);
nlist = (word)hreg | LIST_TAG;
for (i=0; i<l; i++) {
follow(hreg++) = makeint(*(name++));
top = hreg++;
follow(top) = (word)(hreg) | LIST_TAG;
}
follow(top) = nil_sym;
if (!unify(gregc(2), nlist)) {Fail0;}
} /* b_NAME0 */
b_BLDATOM()
/* (X, L), L is known not free, X is known free.
make X to be an atom with name string L */
{
int a, n;
char name[256], *s;
register word op2, op3;
register pw top;
s = name;
n = 0;
op2 = gregc(2);
do {
deref(op2);
if (op2 == nil_sym) break;
if (islist(op2)) {
untag(op2);
op3 = follow(op2);
deref(op3);
if (!isinteger(op3)) {
printf("Error: bldatom, non integer\n");
Fail0; return;}
a = intval(op3);
if(a < 0 || a > 255) {
printf("Error: bldatom, bad integer\n");
Fail0; return;}
*(s++) = a;
n++;
op2 = follow((op2+4));
}
else {
printf("Error: bldstr, non list\n");
Fail0; return;}
} while(1);
ptr = insert(name, n, 0, &perm) | CS_TAG;
if (!unify(gregc(1), ptr)) {Fail0;}
} /* b_BLDATOM */